package service

import (
	"go-admin-server/app/dao"
	"go-admin-server/app/dao/model"
	"go-admin-server/app/dao/repo"
	"go-admin-server/common/assert"
)

var RoleService = new(roleService)

type roleService struct{}

func (s *roleService) Create(role *model.Role) (uint64, error) {
	err := repo.RoleRepo.Create(role)
	return role.ID, err
}

func (s *roleService) List(page, size int) (list []*model.Role, count int64) {
	db := dao.DB.Debug().Model(&model.Role{})
	err := db.Count(&count).Error
	assert.AssertErrNil(err)
	err = db.Limit(size).Offset(size * (page - 1)).Order("created_at desc").Find(&list).Error
	assert.AssertErrNil(err)
	return list, count
}

func (s *roleService) Delete(ids *[]int) error {
	err := dao.DB.Debug().Delete(&model.Role{}, ids).Error
	return err
}
